package com.ldc.composetest.compose_screen

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material.*
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Refresh
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

@Composable
fun TitleBar(title: String, onLeftListener: () -> Unit, onRightListener: () -> Unit) {
    Column(
        modifier = Modifier
            .fillMaxWidth()
            .height(45.dp), horizontalAlignment = Alignment.CenterHorizontally
    ) {
        Row(
            modifier = Modifier.fillMaxSize(),
            horizontalArrangement = Arrangement.SpaceBetween,
            verticalAlignment = Alignment.CenterVertically
        ) {
            IconButton(onClick = onLeftListener) {
                Icon(
                    Icons.Default.ArrowBack,
                    contentDescription = null,
                    modifier = Modifier.size(25.dp)
                )
            }
            // 标题
            Text(text = title, fontSize = 17.sp, overflow = TextOverflow.Ellipsis)

            IconButton(onClick = onRightListener) {
                Icon(
                    Icons.Default.Refresh,
                    contentDescription = null,
                    modifier = Modifier.size(25.dp)
                )
            }
        }
        Divider(
            Modifier
                .height(1.dp)
                .background(MaterialTheme.colors.primary)
        )
    }
}